//
//  WCNMyPrivateSettingVC.m
//  WCN
//
//  Created by wsj2015 on 16/4/7.
//  Copyright © 2016年 ShanghaiCize Trade And Business Co., Ltd. All rights reserved.
//

#import "WCNMyPrivateSettingVC.h"

@interface WCNMyPrivateSettingVC ()


@property (nonatomic,  assign) NSInteger isAllow;

@end

@implementation WCNMyPrivateSettingVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = @"搜索";
    self.tableView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
    
    
    self.isAllow = [[[[WCDefaultManager shareMg] account] searchStatus]integerValue];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cellId"];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:@"cellId" forIndexPath:indexPath];
    cell.textLabel.text = @"允许搜索到我";
    UISwitch *turn =[[UISwitch alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
    [turn addTarget:self action:@selector(turnAction:) forControlEvents:UIControlEventValueChanged];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    turn.on = self.isAllow;
    cell.accessoryView = turn;
    return cell;
   
}
- (void)turnAction:(UISwitch *)turn{
    
    [self postToNet:turn.on];
    
}
- (void)postToNet:(BOOL)isTurn{
    NSMutableDictionary *params =[NSMutableDictionary dictionary];
    CoreSVPLoading(@"正在同步..", NO);
    params[@"searchStatus"] = isTurn?@(1):@(0);
     params[@"nurseId"] = @([[WCDefaultManager shareMg] nurseId]);
    [[WCNetworkAccessManager sharedMg] POST:kAllowSearchedPost parameters:params success:^(NSDictionary *responseObject) {
       
        [[WCDefaultManager shareMg] updatSearchStatus:isTurn];
        CoreSVPSuccess(responseObject[@"data"]);
        
    } failure:nil netError:nil always:^{
        [CoreSVP dismiss];
    }];
  
 
}
- (void)dealloc{
 
}
@end
